(function ($) {
  //主菜单
  const pathMap = ['/guide/about/', '/guide/news/', '/guide/quality/', '/guide/business/', '/guide/suppor/', '/guide/security/']
  //帮助中心菜单
  const helpCenterMenu = ['/guide/register/','/guide/draft-entry/','/guide/draft-trade/','/guide/publish-draft/','/guide/agent/','/guide/cib/']
  var currntPath = window.location.pathname,
      menu_index = pathMap.indexOf(currntPath),
      helpCenterMenu_index = helpCenterMenu.indexOf(currntPath);
  //登录信息
  var userInfo = JSON.parse(localStorage.getItem('userInfo'))
  if (!userInfo) {
    $('.isLogin').hide()
    $('.notLogin').show()
  } else {
    $('.isLogin').show()
    $('.notLogin').hide()
    $('.isLogin .enterpriseName').text(ellipsis(userInfo.enterprise_name,'...',8))
    $('.isLogin .userName').text(userInfo.customer_name)
  }
  //菜单栏添加active效果
  if (menu_index > -1) {
    $('.main .mainMenu ul li').eq(menu_index).children('a').css({ 'background-color': '#ffb307', 'color': '#fff' })
  } else {
    if (helpCenterMenu_index > -1) {
      $('.main .helpCenter ul li').eq(helpCenterMenu_index).children('a').css({ 'background-color': '#ffb307', 'color': '#fff' })
    } else {
      $('.main .mainMenu ul li').eq(1).children('a').css({ 'background-color': '#ffb307', 'color': '#fff' })
    }
  }
  //去我的交易
  $('.enterpriseName, .userName').on('click', function () {
    window.location.href = '/trade.html#/enterprise/info'
  })
  //退出登录
  $('.sign_out').on('click', function () {
    localStorage.removeItem('userInfo');
    window.location.href = '/user.html#/login'
  })
  $('.faq .question').on('click', function (e) {
    // e.preventDefault();
    e.stopPropagation();
    $('.faq .answer').hide()
    $('.collapse').removeClass('expanse');
    $(this).next().show();
    // $(this).next().show('normal', 'linear');
    $('.collapse', this).addClass('expanse');
  })
  //底部工商网监电子标识跳转
  $('.commerceRecord').click(function(){
    window.open('http://218.242.124.22:8081/businessCheck/verifKey.do?showType=extShow&serial=9031000020160601094501000000875554-SAIC_SHOW_310000-20190228165151984080&signData=MEUCIQCX/Iu+HPoQmS0Wzix3GKVXrQOmMjtnXlYX7gQdwQNqKQIgPtPW8h/yE483WHPJSlot9EvDpvAm8I6xxuvIQ6TvlCM=')
  })
  //企业名字数超出隐藏
  function ellipsis (value, replaceStr, n){
    if(!value) return ''
    if(value.length <= n) replaceStr = ''
    let beforeStr = value.split('')
    beforeStr = beforeStr.slice(0, n)
    // beforeStr = [...beforeStr, replaceStr]
    return beforeStr.join('') + replaceStr
  }
})(jQuery);